package com.lbb.utils

import android.app.Activity
import android.content.SharedPreferences


object SpUtil {
    private const val SharedPreferenceUtils = "SharedPreferenceUtils"
    private val sp: SharedPreferences
        get() = Helper.application!!.getSharedPreferences(
            SharedPreferenceUtils,
            Activity.MODE_PRIVATE
        )

    private val editor: SharedPreferences.Editor
        get() = sp.edit()

    fun getStringValue(name: String): String? {
        return sp.getString(name, null)
    }

    fun getBooleanValue(name: String): Boolean {
        return sp.getBoolean(name, false)
    }

    fun getIntValue(name: String): Int {
        return sp.getInt(name, 0)
    }

    fun getLongValue(name: String): Long {
        return sp.getLong(name, 0)
    }

    fun getFloatValue(name: String): Float {
        return sp.getFloat(name, 0f)
    }

    fun setValue(name: String, value: String?) {
        val editor = editor
        editor.putString(name, value)
        editor.commit()
    }

    fun setValue(name: String, value: Boolean) {
        val editor = editor
        editor.putBoolean(name, value)
        editor.commit()
    }

    fun setValue(name: String, value: Int) {
        val editor = editor
        editor.putInt(name, value)
        editor.commit()
    }

    fun setValue(name: String, value: Float) {
        val editor = editor
        editor.putFloat(name, value)
        editor.commit()
    }

    fun setValue(name: String, value: Long) {
        val editor = editor
        editor.putLong(name, value)
        editor.commit()
    }


}